home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / bin / showexternal < prev    next >
Encoding:
Text File  |  1995-07-03  |  5.7 KB  |  242 lines

  1. :
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13.  
  14. # Conversion from C shell to Bourne shell by Z-Code Software Corp.
  15. # Conversion Copyright (c) 1992 Z-Code Software Corp.
  16. # Permission to use, copy, modify, and distribute this material
  17. # for any purpose and without fee is hereby granted, provided
  18. # that the above copyright notice and this permission notice
  19. # appear in all copies, and that the name of Z-Code Software not
  20. # be used in advertising or publicity pertaining to this
  21. # material without the specific, prior written permission
  22. # of an authorized representative of Z-Code.  Z-CODE SOFTWARE
  23. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  24. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  25. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  26.  
  27. if test -f /usr/lib/sendmail
  28. then
  29.     MAILCOMMAND=/usr/lib/sendmail
  30. else
  31.     MAILCOMMAND=/bin/mail
  32. fi
  33.  
  34. if test -z "$3"
  35. then
  36.     echo "Usage: showexternal body-file access-type name [site [directory [mode]]]"
  37.     exit 1
  38. fi
  39.  
  40. if [ -z "$METAMAIL_TMPDIR" ]
  41. then
  42.     METAMAIL_TMPDIR=/tmp
  43. fi
  44.  
  45. bodyfile=$1
  46. atype=`echo $2 | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
  47. name=$3
  48.  
  49. site=$4
  50.  
  51. dir=$5
  52.  
  53. mode=$6
  54.  
  55. ctype=`grep -i content-type: $bodyfile | sed -e 's/............: //'`
  56. cenc=`grep -i content-transfer-encoding: $bodyfile | sed -e 's/.........................: //'`
  57. username=""
  58. pass=""
  59. TMPDIR=$METAMAIL_TMPDIR/XXXternal.$$
  60. trap 'rmdir "$TMPDIR" >/dev/null 2>&1' 1 2 3 15
  61. mkdir $TMPDIR
  62. cd $TMPDIR
  63. NEWNAME="mm.ext.$$"
  64. NEEDSCONFIRMATION=1
  65.  
  66. case $atype in
  67.     anon-ftp)
  68.         echo "This mail message contains a POINTER (reference) to data that is "
  69.         echo not included in the message itself.  Rather, the data can be retrieved 
  70.         echo automatically using anonymous FTP to a site on the network. ;;
  71.         
  72.     ftp)
  73.         echo "This mail message contains a POINTER (reference) to data that is "
  74.         echo not included in the message itself.  Rather, the data can be retrieved 
  75.         echo automatically using the FTP protocol to a site on the network. ;;
  76.  
  77.     mail-server)
  78.         cat > $METAMAIL_TMPDIR/ext.junk.$$ <<!
  79. This mail message contains a POINTER (reference) to data that is not
  80. included in the message itself.  Rather, the data can be retrieved by
  81. sending a special mail message to a mail server on the network.
  82. However, doing this automatically is slightly dangerous, because
  83. someone might be using this mechanism to cause YOU to send obnoxious
  84. mail.  For that reason, the mail message that WOULD be sent is being
  85. shown to you first for your approval.
  86.  
  87. This is the message that will be sent if you choose to go ahead and
  88. retrieve the external data:
  89.  
  90. To: ${name}@${site}:
  91. Subject: Automated Mail Server Request
  92.  
  93. !
  94.         cat $bodyfile >> $METAMAIL_TMPDIR/ext.junk.$$
  95.         more $METAMAIL_TMPDIR/ext.junk.$$
  96.         rm $METAMAIL_TMPDIR/ext.junk.$$ ;;
  97.  
  98.     *)
  99.         NEEDSCONFIRMATION=0 ;;
  100. esac
  101.  
  102. if test $NEEDSCONFIRMATION -ne 0
  103. then
  104.     echo ""
  105.     echo_n "Do you want to proceed with retrieving the external data? [y] "
  106.     read ANS
  107.     case "$ANS" in
  108.         [Nn]*) rm -rf $TMPDIR; exit 0 ;;
  109.     esac
  110. fi
  111.  
  112. case "$atype" in
  113.     anon-ftp | ftp)
  114.         case "$atype" in
  115.         anon-ftp )
  116.             username=anonymous
  117.             pass=`whoami`@`hostname`
  118.             ;;
  119.         esac
  120.  
  121.         if test -z "$site"
  122.         then
  123.             echo_n "Site for ftp access: "
  124.             read site
  125.         fi
  126.         if test -z "$username"
  127.         then
  128.             echo_n "User name at site ${site}: "
  129.             read username
  130.         fi
  131.         if test -z "$pass"
  132.         then
  133.             echo_n "Password for user $username at site ${site}: "
  134.             stty -echo
  135.             read pass
  136.             stty echo
  137.             echo ""
  138.         fi
  139.         if test -z "$dir"
  140.         then
  141.             DIRCMD=""
  142.         else
  143.             DIRCMD="cd $dir"
  144.         fi
  145.         if test -z "$mode"
  146.         then
  147.             MODECMD=""
  148.         else
  149.             MODECMD="type $mode"
  150.         fi
  151.         echo OBTAINING MESSAGE BODY USING FTP
  152.         echo SITE: $site USER: $username
  153.         ${FTP:-ftp} -n <<!
  154. open $site
  155. user $username $pass
  156. $DIRCMD
  157. $MODECMD
  158. get $name $NEWNAME
  159. quit
  160. !
  161.         if test ! -r "$NEWNAME"
  162.         then
  163.             echo FTP failed.
  164.             rm -rf $TMPDIR
  165.             exit 1
  166.         fi
  167.         ;;
  168.  
  169.     afs|local-file)
  170.         if test ! -r $name
  171.         then
  172.             echo File not found
  173.             rm -rf $TMPDIR
  174.             exit 1
  175.         fi
  176.         NEWNAME=$name
  177.         echo GETTING BODY FROM FILE NAMED: $NEWNAME ;;
  178.  
  179.     mail-server)
  180.         if test -z "$bodyfile"
  181.         then
  182.             echo mail-server access-type requires a body file
  183.             rm -rf $TMPDIR
  184.             exit 1
  185.         fi
  186.         echo Subject: Automated Mail Server Request > $NEWNAME
  187.         echo To: ${name}@${site} >> $NEWNAME
  188.         echo "" >> $NEWNAME
  189.         cat $bodyfile >> $NEWNAME
  190.         $MAILCOMMAND -t < $NEWNAME
  191.         if test $? -ne 0
  192.         then
  193.             echo sendmail failed
  194.             rm -rf $TMPDIR
  195.             exit 1
  196.         fi
  197.         rm -rf $TMPDIR
  198.         echo Your $ctype data has been requested from a mail server.
  199.         exit 0 ;;
  200.     *)
  201.         echo UNRECOGNIZED ACCESS-TYPE
  202.         rm -rf $TMPDIR
  203.         exit 1 ;;
  204. esac
  205.  
  206. if test "$cenc" = base64
  207. then
  208.     mmencode -u -b < $NEWNAME > OUT
  209.     mv OUT $NEWNAME
  210. elif test "$cenc" = quoted-printable
  211. then
  212.     mmencode -u -q < $NEWNAME > OUT
  213.     mv OUT $NEWNAME
  214. fi
  215.  
  216. case "$atype" in
  217.     local-file ) metamail -b -c $ctype $NEWNAME ;;
  218.     * ) metamail -b -c "$ctype" $TMPDIR/$NEWNAME ;;
  219. esac
  220.  
  221. if test $? -ne 0
  222. then
  223.     echo metamail failed
  224.     rm -rf $TMPDIR
  225.     exit 1
  226. fi
  227.  
  228. if test ! "$NEWNAME" = "$name"
  229. then
  230.     echo ""
  231.     echo The data just displayed is stored in the file $TMPDIR/$NEWNAME
  232.     echo "Do you want to delete it?"
  233.     rm -i $NEWNAME
  234. fi
  235.  
  236. if test ! -r ${TMPDIR}/${NEWNAME}
  237. then
  238.     cd /
  239.     rmdir $TMPDIR
  240. fi
  241.